package com.thinkgem.jeesite.common.config;

import java.util.ResourceBundle;

import org.apache.commons.lang3.StringEscapeUtils;

import com.thinkgem.jeesite.common.utils.StringUtils;

public class Config {
	/**
	 * 是否是调试模式
	 * @return
	 */
	public static Boolean isDebugMode() {
		String dm = Global.getConfig("debugMode");
		return "true".equals(dm) || "1".equals(dm);
	}
	
	/**
	 * 是否启用多租户
	 * @return
	 */
	public static Boolean isMultiTenant() {
		String dm = Global.getConfig("multiTenant.enable");
		return "true".equals(dm) || "1".equals(dm);
	}
	
	/**
	 * 是否是微信模式
	 * @return
	 */
	public static Boolean isWechatMode() {
		String dm = Global.getConfig("wechatMode");
		return Config.isDebugMode() ? false : "true".equals(dm) || "1".equals(dm);
	}
	
	/**
	 * 获取下载图片的路径
	 */
	public static String getDownImgUrl(){
		return Global.getConfig("downloadUrl");
	}
	
	/**
	 * 是否启用微信验证码
	 * @return
	 */
	public static Boolean isSmsWechatEnabled() {
		String dm = Global.getConfig("sms.wechat.enabled");
		return "true".equals(dm) || "1".equals(dm);
	}
	
	/**
	 * 是否启用分布式缓存
	 * @return
	 */
	public static Boolean isCacheDistributedEnabled() {
		String dm = Global.getConfig("cache.distributed.enable");
		return "true".equals(dm) || "1".equals(dm);
	}
	
	/**
	 * 是否启用上传文件启动全路径
	 * @return
	 */
	public static Boolean isUserfilesFullUrlEnabled() {
		String dm = Global.getConfig("userfiles.fullurl.enabled");
		return "true".equals(dm) || "1".equals(dm);
	}	
	
	/**
	 * 是否启用微信机器人
	 * @return
	 */
	public static Boolean isWechatRobotEnabled() {
		String dm = Global.getConfig("wechat.robot.enabled");
		
		if(StringUtils.isBlank(dm)) {
			dm = ResourceBundle.getBundle("wechat").getString("wechat.robot.enabled");
		}
		
		return "true".equals(dm) || "1".equals(dm);
	}
	
	/**
	 * 是否启用微信关注回复
	 * @return
	 */
	public static Boolean isWechatSubScriptingEnabled() {
		String dm = Global.getConfig("wechat.subScripting.enabled");
		
		if(StringUtils.isBlank(dm)) {
			dm = ResourceBundle.getBundle("wechat").getString("wechat.subScripting.enabled");
		}
		
		return "true".equals(dm) || "1".equals(dm);
	}
	
	/**
	 * 微信关注回复
	 * @return
	 */
	public static String wechatSubScripting() {
		String subScripting = StringEscapeUtils.unescapeJava(Global.getConfig("wechat.subScripting"));
		
		if(StringUtils.isBlank(subScripting)) {
			subScripting = ResourceBundle.getBundle("wechat").getString("wechat.subScripting");
		}
		return subScripting;
	}
	
	/**
	 * 微信前端的跳转页面
	 * @return
	 */
	public static String wechatRedirectUrl() {
		return Global.getConfig("wechat.redirect.url");
	}
	
	/**
	 * 默认最顶层部门Id
	 * @return
	 */
	public static String defaultRootOfficeId() {
		return Global.getConfig("sys.office.default.root");
	}
	/**
	 * 获取运行模式
	 * @return
	 */
	public static String getRunMode() {
		String result="web";
		if(isWechatMode()) {
			result="wechat";
		}
		return result;
	}
}
